﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ViewModelBaseTest.cs" company="Concept Architecture">
//   (c) 2010 Muhammad Umer Farooq
// </copyright>
// <summary>
//   This is a test class for ViewModelBaseTest and is intended
//   to contain all ViewModelBaseTest Unit Tests
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Hisaab.Client.Common.Tests.BaseClasses
{
    using Hisaab.Client.Common.BaseClasses;

    using Microsoft.VisualStudio.TestTools.UnitTesting;

    /// <summary>
    /// This is a test class for ViewModelBaseTest and is intended
    /// to contain all ViewModelBaseTest Unit Tests
    /// </summary>
    [TestClass]
    public class ViewModelBaseTest
    {
        /// <summary>
        /// Titles the should raise notify property change.
        /// </summary>
        [TestMethod]
        public void TitleShouldRaiseNotifyPropertyChange()
        {
            var vm = new ViewModelBaseImpl();
            var tester = new NotifyPropertyChangedTester(vm);

            vm.Title = "New title";

            tester.AssertChange(0, "Title");
        }

        /// <summary>
        /// Images the should raise notify property change.
        /// </summary>
        [TestMethod]
        public void ImageShouldRaiseNotifyPropertyChange()
        {
            var vm = new ViewModelBaseImpl();
            var tester = new NotifyPropertyChangedTester(vm);

            vm.Image = null;

            tester.AssertChange(0, "Image");
        }

        /// <summary>
        /// Images the small should raise notify property change.
        /// </summary>
        [TestMethod]
        public void ImageSmallShouldRaiseNotifyPropertyChange()
        {
            var vm = new ViewModelBaseImpl();
            var tester = new NotifyPropertyChangedTester(vm);

            vm.ImageSmall = null;

            tester.AssertChange(0, "ImageSmall");
        }

        /// <summary>
        /// Raises the property changed event should not raise notify property change if ignore flag is true.
        /// </summary>
        [TestMethod]
        public void RaisePropertyChangedEventShouldNotRaiseNotifyPropertyChangeIfIgnoreFlagIsTrue()
        {
            var vm = new ViewModelBaseImpl();
            var tester = new NotifyPropertyChangedTester(vm);

            vm.IgnorePropertyChangeEvents = true;
            vm.RaisePropertyChangedEvent("Title");

            Assert.AreEqual(0, tester.Changes.Count);
        }

        /// <summary>
        /// Raises the property changed event should raise notify property change if N subscribed.
        /// </summary>
        [TestMethod]
        public void RaisePropertyChangedEventShouldRaiseNotifyPropertyChangeIfNSubscribed()
        {
            var vm = new ViewModelBaseImpl();
            var tester = new NotifyPropertyChangedTester(vm);

            vm.RaisePropertyChangedEvent("Title");
            tester.AssertChange(0, "Title");
        }

        /// <summary>
        /// Raises the property changed event should not raise notify property change if ignore flag is true.
        /// </summary>
        [TestMethod]
        public void RaisePropertyChangingEventShouldNotRaiseNotifyPropertyChangeIfIgnoreFlagIsTrue()
        {
            var vm = new ViewModelBaseImpl();
            var tester = new NotifyPropertyChangedTester(vm);

            vm.IgnorePropertyChangeEvents = true;
            vm.RaisePropertyChangingEvent("Title");

            Assert.AreEqual(0, tester.Changes.Count);
        }

        /// <summary>
        /// Raises the property changed event should raise notify property change if N subscribed.
        /// </summary>
        [TestMethod]
        public void RaisePropertyChangingEventShouldRaiseNotifyPropertyChangeIfNSubscribed()
        {
            var vm = new ViewModelBaseImpl();
            var tester = new NotifyPropertyChangedTester(vm);

            vm.RaisePropertyChangingEvent("Title");
            tester.AssertChange(0, "Title");
        }

        /// <summary>
        /// Defines the <seealso cref="ViewModelBaseImpl"/> type.
        /// </summary>
        private class ViewModelBaseImpl : ViewModelBase
        {
        }
    }
}